package com.wkhyapp.lm.utils;

import android.content.Context;
import android.util.TypedValue;

/**
 * Created by fangzehua on 2017/7/13.
 * 淘宝客项目
 * 邮箱:442947949@qq.com
 * QQ群:567598491
 */

public class DensityUtil {


    /**
     * 将单位为dip的值转换成单位为px的值
     *
     * @param context Context
     * @param dipValue dip值
     * @return px值
     */
    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }


    public static int dipToPix(Context context, int dip) {
        int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics());
        return size;
    }

}
